<meta http-equiv="X-UA-Compatible" content="IE=10" />
<meta content="text/html; charset=UTF-8; X-Content-Type-Options=nosniff" http-equiv="Content-Type" />
<script src="js/app.api.js"></script>
	<script src="js/app.domain.js"></script>

	<style type="text/css">
		.appstools_panel{border-right: 1px solid #EFEFEF;  float: left; position:relative; width:256px;}
		/*appstools to custom css*/
		.apps_tools_panel_functions{width: 100%; background-color: #39bf71; }

		#appstools_main_order_by_name{color: white; display: none; }
		.appstools_panel_top{color:white; text-align: center; background-color: #32a662; }
		.appstools_panel_body{background-color: #39bf71; height: 100%; }
		
		.appstools_min_panel_app_icon{display:block; margin:0 auto;}
		.appstools_min_panel_app_name_font{color:white;  text-align:center; }

		.appstools_max_panel_app_name_font{color:white;}
		.appstools_max_panel_app_des_font{color:white;line-height: 12px; }
		.wp_w_55_3{width: 55.3px; } .margin_020{margin: 0 20px; }
		.wp_appstools_hand{
			 cursor:pointer;
		}
		#appstools_app_detail_window {
    			border: 1px solid #EAEAEA;
		}
		.wp_mt_ne10{
			margin-top: -10px;
		}
		.wp_appstools_title{
			line-height: 20px;
		}
		.apps_tools_button{
			background-color: #32a662!important;
		}
		#apps_tools_order_by_time{color: white;}
		#apps_tools_order_by_frequent{color: white;}
		.wp_appstools_feedback{
			color: #00ffff;
		}
		.apps_tools_white_font_color{
			color: white;
		}
		.text_one_line_overflow {
			  display:block;
			  word-break:keep-all;
			  white-space:nowrap;
			  overflow:hidden;
			  text-overflow:ellipsis;
			  -o-text-overflow:ellipsis
		}
		.apps_tools_input_color{
			color: black;
		}
		#apps_tools_search_view{
			background-color: #39BF71;
			display: none;
		}
		#apps_tools_search_view .k-i-calendar{display: none;}
		#apps_tools_search_view .k-select{width: 100%;}
		.apps_tools_hr{height:1px;border:none;border-top:1px solid #e5e5e5;}
		#apps_tools_search_result_back{color: #00ffff;text-decoration: none;}

		#apps_tools_alpa_search{
			overflow: hidden;
		}
		#apps_tools_alpa_search ul{
            position: absolute;
		    left: 233px;
		    top: 45px;
		    text-align: center;
		    height:93%;
		    font-size: 14px;
        }
        #apps_tools_alpa_search li{
            cursor: pointer;
            list-style: none;
            color: white;
            /*border-bottom: 1px solid #39bf71;*/
            width: 15px;
        }
        #apptools_extend_tooltip_img{
        	position: absolute;
        	z-index: 99999999;
        	left: 17px;
        	top:50px;
        	display: none;
        }
        #apptools_tooltip_img{
        	display: none;
        	position:relative;
        	left: 50px;
        	z-index : 999999999;
        }
        #apps_tools_no_alpha_result{
        	position: absolute;
        	z-index: 99999999;
        	left: 18px;
        	top: 60px;
        	font-size: 14px;
        	color: white;
        	display: none;
        }
        #apps_tools_search_zero_result{
        	position: absolute;
        	z-index: 99999999;
        	left: 25px;
        	top: 150px;
        	font-size: 14px;
        	color: white;
        	display: none;
        }
       .apps_tools_no_result_p {
        	text-align: center;
			text-overflow: ellipsis;
			width: 700px;
			word-wrap: break-word;
		}
    </style>
	
	<div class="appstools_panel_div appstools_panel" id="appstools_panel">  
		<div id="appstools_panel_top" class="appstools_panel_top wp_h_20 wp_fz_14 wp_appstools_title">
			Applications & Tools
			<i id="appstools_panel_resize_icon" class="main_common_f_13_13 panel_resize right wp_mr_5 wp_mt_3 wp_appstools_hand"></i>
			<img id="apptools_tooltip_img" src="imgs/beganAppTool.png">
		</div>
		<div class="apps_tools_panel_functions wp_h_30 wp_pt_10">
			<button id="wp_apps_tools_register_button" type="button" class="k-button left wp_w_105 wp_h_18 wp_fz_11 wp_ml_17 apps_tools_button"  onclick="wp_apps_tools.clickRegisterButton()"
			>Register My Apps</button>
			<button id="wp_apps_tools_launch_button" type="button" class="k-button left wp_w_85 wp_h_18 wp_fz_11 wp_ml_25 apps_tools_button apps_tools_hide_button" 
				onclick="wp_apps_tools.clickLaunchButton()">Edit My Apps</button>
			<i id="appstools_search" title="Search" class="main_common_g_11_11 right wp_mr_10 wp_mt_5 wp_appstools_hand"  onclick="wp_apps_tools.openOrCloseSearchPanel()"></i>
			<img id="apptools_extend_tooltip_img" src="imgs/beganAppExpand.png">
			<span id="apps_tools_no_alpha_result"></span>
		</div>

		<div id="apps_tools_search_view" class="wp_w_768  wp_pb_15 left">
			<span type="text" class="left wp_ml_17 wp_fz_11 wp_mt_3 apps_tools_white_font_color">Keywords&nbsp;&nbsp;</span>
			<div class="k-textbox wp_searchbar">
	            <input id="apps_tools_search_keywords_input" type="text" maxlength="255" onkeypress="wp_apps_tools.enterSearchBtn(event)">
	            <i class="k-icon k-i-search left wp_appstools_hand" title="Search" onclick="wp_apps_tools.clickSearchIcon()">&nbsp;</i>
	        </div>
			<hr class="apps_tools_hr wp_w_743 wp_mt_9 wp_mb_10 left">
			<div class="wp_w_700 wp_ml_17 wp_h_20 wp_mb_10 left" id="apps_tools_search_result_view">
		    	<a class=" wp_ml_17 wp_fz_12 wp_appstools_hand" id="apps_tools_search_result_back" onclick="wp_apps_tools.clickBackToAll()">Back to all</a>
		    	<span class="wp_fz_12 apps_tools_white_font_color">&nbsp;&gt;&nbsp;Showing&nbsp;<span  data-bind="text: resultcount" id="apps_tools_search_result_count"></span>&nbsp;result(s) for&nbsp;<span id="apps_tools_search_result_keywords" data-bind="text: keywords"></span></span>
			</div>
			<span id="apps_tools_search_zero_result" class="app_tool_highlight apps_tools_no_result_p"></span>
		</div>
		<div id="apps_tools_alpa_search" data-alpa-name="apps_tools_alpa_search">	
			<div id="appstools_min_panel_div" class="appstools_panel_body wp_pl_7 wp_pr_15"></div>
			<div id="appstools_max_panel_div" class="appstools_panel_body wp_pl_16 wp_pr_25"></div>
		</div>
	</div>

	<script type="text/x-kendo-template" id="appstools_panel_min_template">
		<div class="left wp_w_60 wp_mb_20 wp_appstools_hand" style="#: data.mid_mar # ">
			<img id="appImage" class="appstools_min_panel_app_icon wp_w_40 wp_h_40" src="#: data.AppImage #" onerror="onAPPDefaultThumbnailWanted(this)" 
			         onclick="wp_apps_tools.clickAppIcon(this,#:data.AppID#,'#:data.AppURL#')">
			<div id="appTitle_min" class="appstools_min_panel_app_name_font wp_mt_10 wp_fz_12 text_one_line_overflow" title="#: data.AppTitle #" onclick="wp_apps_tools.clickAppIcon(this,#:data.AppID#,'#:data.AppURL#')"><span>#: data.AppTitle #</span></div>
		</div>
	</script>

	<script type="text/x-kendo-template" id="appstools_panel_max_template">		
		<div class="left wp_h_78  wp_mb_20" style="#: data.mid_mar # ">
			<div class="left">
				<img id="appIcon" class="wp_w_40 wp_h_40 wp_appstools_hand"  src="#: data.AppImage #" onerror="onAPPDefaultThumbnailWanted(this)" onclick="wp_apps_tools.clickAppIcon(this,#:data.AppID#,'#:data.AppUrl#')" >
			</div>
			<div class="left wp_w_151 wp_ml_15 wp_mt_3 appstools_app_content_div">
				<div class="appstools_max_panel_app_name_font wp_fz_14 wp_mt_ne6">
					<span id="appTitle_max" class="wp_w_130 wp_h_20 left wp_lh_20 wp_appstools_hand text_one_line_overflow app_tool_highlight" title="#: data.AppTitle #" onclick="wp_apps_tools.clickAppIcon(this,#:data.AppID#,'#:data.AppUrl#')">#: data.AppTitle #</span>
					#if(data.IsBookmarked){#
						<i id="bookMarked" class="main_smartstream_ab_8_8 right wp_ml_10 wp_mt_6 appstools_main_bookmark wp_appstools_hand" title="Unbookmark" onclick="wp_apps_tools.clickBookMark(this,#:data.AppID#)"></i>
					#}else{#
						<i id="bookMarked" class="main_smartstream_ac_8_8 right wp_ml_10 wp_mt_6 appstools_main_bookmark wp_appstools_hand" title="Bookmark" onclick="wp_apps_tools.clickBookMark(this,#:data.AppID#)"></i>
					#}# 
					<div class="clear"></div>
			 	</div>
			 	<p id="appDescription" class="appstools_max_panel_app_des_font text_one_line_overflow wp_fz_12 wp_appstools_hand app_tool_highlight" title="#: data.AppDescription #" onclick="wp_apps_tools.clickAppIcon(this,#:data.AppID#,'#:data.AppUrl#')">#: data.AppDescription #</p>
				<div class="wp_fz_12 wp_mt_5 wp_appstools_feedback">
					<span id="reviewsLink" class="left wp_mt_ne2 wp_appstools_hand" onclick="wp_apps_tools.openAPPDetail(this,#:data.AppID#)">Reviews:</span> 
					<div class="left wp_ml_10">
						#for(var i=0;i<5;i++){#
							#if((i+1)<=data.Ratings){#
								<i id="ratings" class="main_smartstream_g_10_10"  data-wp-tool-feedback-starcount="#:i #"></i>
							#}else{#
								#var rate=Math.abs(i+1-data.Ratings);#
								#if(rate>=0.5&&rate<1){#
									<i id="ratings" class="main_common_r_10_10"  data-wp-tool-feedback-starcount="#:i #"></i>
								#}else{#
									<i id="ratings" class="main_smartstream_h_10_10"  data-wp-tool-feedback-starcount="#:i #"></i>
								#}#	
							#}#
						#}#
					</div>
				</div>
				<div class="wp_fz_12 left apps_tools_white_font_color">
					<span id="launchCount" class="LaunchCount" title="Launch count">#: data.LaunchCount # User(s)</span>
					<span>|</span>
					#if(data.IsLiked){#
						<i id="unlike" class="main_smartstream_t_8_8 wp_mt_3 wp_appstools_hand" onclick="wp_apps_tools.clickLike(this,#:data.AppID#)" title="Unlike"></i>
					#}else{#
						<i id="like" class="app_tools_f_10_10 wp_mt_3 wp_appstools_hand" onclick="wp_apps_tools.clickLike(this,#:data.AppID#)" title="Like"></i>
					#}# 
					#if(data.LikesCount>0){#
						<span id="likesCount" class="wp_appstools_hand wp_appstools_like_count" onclick="wp_apps_tools.getLikedUsers(this,#:data.AppID#)">(#: data.LikesCount #)</span>
					#}else{#
						<span id="likesCount" class="wp_appstools_like_count" onclick="wp_apps_tools.getLikedUsers(this,#:data.AppID#)">(#: data.LikesCount #)</span>
					#}#
					
				</div>
		
			</div>
		</div>
	</script>

    <script>
    var wp_apps_tools = (function() {
    	var minPageTmpl = $('#appstools_min_panel_div');
        var minDataTmpl = $('#appstools_panel_min_template');
        var maxPageTmpl = $('#appstools_max_panel_div');
        var maxDataTmpl = $('#appstools_panel_max_template');
    	var app_tool_app_index="";
    	var alert_title="Error Message";
    	//------------------------------start offset
    	var allAPPSOffset=0;
	    var allNewAppsStartCount=10;
	    var allNewOffset=10;
	    var letterSearchTool;
	    var oldAllAppList;
	    var newALLAppList;
	    var maxStartCount=Math.ceil((Screen.bodyHeight-$('#wp_header').height())/62*3);
	    var minStartCount=Math.ceil((Screen.bodyHeight-$('#wp_header').height())/85*3);
	    var isEndAll=false;
	    var isEndHome=false;
	    var isFirstLoad=true;

    	var homeAPPsOffset=0;
		var oldhomeAppsList;
		var newHomeAppsList;
		var isShowSreachKeywordsNull=false;
		var loading;
		var useragent = Workport.getBrowser();
		var tool_letter = "";
		
    	//-------------------------------start offset end
    	function refreshAfterDelete(deleteIndex){
			oldAllAppList.splice(deleteIndex, 1);
			wp_apps_tools.render(appstools_handel_style_of_datasource(oldAllAppList,"oldmax"),maxDataTmpl,maxPageTmpl);
			shortDescription();
		}

	    function appstools_zoomin_cb () {
	    	
	    	minPageTmpl.hide();
	    	minPageTmpl.empty()
	    	maxPageTmpl.show();
	    	$('#appstools_max_panel_div').css('padding-right','15px')
	        $('.appstools_panel_div').addClass('wp_p_max');
	        $('.appstools_panel_div').css({width:"768"});
	        wp_apps_tools_enlargeIwantoPanel();
	        $("#appstools_main_order_by_name").css({display:"inline"});
	        $("#appstools_panel_resize_icon").toggleClass("main_common_f_13_13 main_common_m_13_13");
	        $('#apps_tools_alpa_search').css('display','block');

	    }
	    function appstools_zoomout_cb() {
	    	maxPageTmpl.hide();
	    	maxPageTmpl.empty()
	    	minPageTmpl.show();
	        $('.appstools_panel_div').removeClass('wp_p_max');
	        $('.appstools_panel_div').css({width:"256"});
	        wp_apps_tools_decreaseIwantoPanel();
	        $("#appstools_main_order_by_name").css({display:"none"});
	        $("#appstools_panel_resize_icon").toggleClass("main_common_f_13_13 main_common_m_13_13");
	    }

	    function apps_tools_closeSearchPanel(){
			$("#apps_tools_search_view").hide();
			$("#apps_tools_search_result_view").hide();
			$("#apps_tools_search_keywords_input").val("");
		}
		function wp_apps_tools_enlargeIwantoPanel(){
			//show button
			$(".apps_tools_hide_button").show();
			wp_apps_tools.render([],maxDataTmpl,maxPageTmpl);
			$("#appstools_max_panel_div").parent().show();
			$("#appstools_min_panel_div").parent().hide();
			$('#apps_tools_alpa_search').css('width',"768");
			$('#apps_tools_alpa_search').find('ul').css("left","745px");
			$('#apptools_tooltip_img').hide();
			$('#apps_tools_no_alpha_result').hide();
			letterSearchTool.update();
			letterSearchTool.cancleHighLight();
			wp_apps_tools.showLoading(loading,$('#appstools_panel'),false,false);
			// Call getHomeApp API
			var reqdata={offset:0,count:maxStartCount,filterBy:"Dummy String",orderBy:"Dummy String",mode:"Limited"};
			Workport.AppAPI.getAllApp(getAllAppsListCallback,reqdata);
		}

		function wp_apps_tools_decreaseIwantoPanel(){
			//hide button
			$(".apps_tools_hide_button").hide();
			wp_apps_tools.render([],minDataTmpl,minPageTmpl);
			$("#appstools_max_panel_div").parent().hide();
			$("#appstools_min_panel_div").parent().show();
			apps_tools_closeSearchPanel();
			$('#apps_tools_alpa_search').css('width',"256");
			$('#apps_tools_alpa_search').find('ul').css("left","233px");
			$('#apptools_extend_tooltip_img').hide();
			$('#apps_tools_no_alpha_result').hide();
			if(letterSearchTool){
				letterSearchTool.update();
				letterSearchTool.cancleHighLight();
				tool_letter = "";
			}
			wp_apps_tools.showLoading(loading,$('#appstools_panel'),false,false);
			// Call getHomeApp API
			var reqdata={offset:0,count:minStartCount,filterBy:"Dummy String",orderBy:"Dummy String",mode:"Limited"};
			Workport.AppAPI.getHomeApp(getAppsToolsHomeListCallback,reqdata);
		}


		//call back of API
		function getAppsToolsHomeListCallback(data, httpCode){
			loading.hide();
			if(data.ResponseCode=="WP1022"){
					isEndHome=data.IsEnd;
					if(homeAPPsOffset==0){
						wp_apps_tools.render(appstools_handel_style_of_datasource(data.GetHmeApps,"min"),minDataTmpl,minPageTmpl);
			  			oldhomeAppsList=data.GetHmeApps;
			  			if(data.GetHmeApps.length<minStartCount){
			  				homeAPPsOffset=0;
			  				allNewAppsStartCount=minStartCount;
			  			}else{
			  				homeAPPsOffset+=minStartCount;
			  				allNewAppsStartCount=allNewOffset;
			  			}
			  		}else{
			  			var oldCount=oldhomeAppsList.length;
		  				newHomeAppsList=oldhomeAppsList.concat(data.GetHmeApps);
	  					homeAPPsOffset+=data.GetHmeApps.length;
	  					oldhomeAppsList=newHomeAppsList;
		  				wp_apps_tools.render(appstools_handel_style_of_datasource(data.GetHmeApps,"newmin",oldCount),minDataTmpl,minPageTmpl);
			  		}
				}else if(data.ResponseCode=="WP2021"){
					if(homeAPPsOffset==0){
						$('#apptools_tooltip_img').show();
						setTimeout(function(){
                            $('#apptools_tooltip_img').hide();
                        },2000);
					}
				}else{
					Workport.utils.alertMsg(alert_title,data.ResponseMessage,function(_data){});
				}
				if(isFirstLoad){
	  				setAppCount();
	  				isFirstLoad=false;
			  	}
		}

		function getAllAppsListCallback(data, httpCode){
			loading.hide();
			if(data.ResponseCode=="WP1022"){
					$('#apptools_extend_tooltip_img').hide();
					isEndAll=data.IsEnd;
					if(allAPPSOffset==0){
			  			wp_apps_tools.render(appstools_handel_style_of_datasource(data.GetApps,"max"),maxDataTmpl,maxPageTmpl);
			  			oldAllAppList=data.GetApps;
			  			if(data.GetApps.length<maxStartCount){
			  				allAPPSOffset=0;
			  				allNewAppsStartCount=maxStartCount;
			  			}else{
			  				allAPPSOffset+=maxStartCount;
			  				allNewAppsStartCount=allNewOffset;
			  			}
			  		}else{
			  			var oldCount=oldAllAppList.length;
		  				newALLAppList=oldAllAppList.concat(data.GetApps);
	  					allAPPSOffset+=data.GetApps.length;
	  					oldAllAppList=newALLAppList;
		  				wp_apps_tools.render(appstools_handel_style_of_datasource(data.GetApps,"newmax",oldCount),maxDataTmpl,maxPageTmpl);
			  		}
			  		shortDescription();
			  		
			}else if(data.ResponseCode=="WP2021"){
				if(allAPPSOffset==0){
					$('#apptools_extend_tooltip_img').show();
					setTimeout(function(){
                        $('#apptools_extend_tooltip_img').hide();
                    },2000);
				}
			}else{
				Workport.utils.alertMsg(alert_title,data.ResponseMessage,function(_data){});
			}
		}

		function shortDescription(){
			//short description text
			$(".appstools_app_content_div").each(function(i){
			    var $p = $("p", $(this)).eq(0);
			    while ($p.outerHeight() > 24) {
			        $p.text($p.text().replace(/(\s)*([a-zA-Z0-9]+|\W)(\.\.\.)?$/, "..."));
			    };
			});
		}
		
		//Tool function
		function appstools_handel_style_of_datasource(datasource,flag,oldLength){
			if(flag=="oldmax"){
				for(var i=0;i<datasource.length;i++){
					if(i==1 ||i%3==1){
						datasource[i].mid_mar="margin-left:50px;margin-right:50px;";
					}else{
						datasource[i].mid_mar="";
					}
				}
			}else if(flag=="newmin"){
				for(var i=oldLength;i<(datasource.length+oldLength);i++){
					if(i==1 ||i%3==1){
						datasource[i-oldLength].mid_mar="margin-left:23px;margin-right:23px;";
					}
				}
			}else if(flag=="newmax"){
				for(var i=oldLength;i<(datasource.length+oldLength);i++){
					if(i==1 ||i%3==1){
						datasource[i-oldLength].mid_mar="margin-left:50px;margin-right:50px;";
					}
				}
			}else{
				for(var i=0;i<datasource.length;i++){
					if(i==1 ||i%3==1){
						if(flag=="min"){
							datasource[i].mid_mar="margin-left:23px;margin-right:23px;";
						}
						if(flag=="max"){
							datasource[i].mid_mar="margin-left:50px;margin-right:50px;";
						}
					}
				}
			}
			return datasource;
		}


		

		return {
			get_appstools_zoomin_cb:function(){
				allAPPSOffset = 0 ;
				homeAPPsOffset=0;
				if(useragent != 'ipad'){
					$('#appstools_min_panel_div').slimScroll({ scrollTo: '-500px',disableFadeOut:true });
				}
				appstools_zoomin_cb();
			},
			get_appstools_zoomout_cb:function(){
				allAPPSOffset = 0 ;
				homeAPPsOffset=0;
				if(useragent != 'ipad'){
					$('#appstools_max_panel_div').slimScroll({ scrollTo: '-500px',disableFadeOut:true });
				}
				appstools_zoomout_cb();
			},
			getNewAllAppsList:function(){
				wp_apps_tools.showLoading(loading,$('#appstools_panel'),true,true);
				var reqdata={ offset: allAPPSOffset, count: allNewAppsStartCount, orderBy:"Dummy String",filterBy:"Dummy String",mode:"Limited"};
				Workport.AppAPI.getAllApp(getAllAppsListCallback,reqdata);
			},
			getNewHomeAppsList:function(){
				wp_apps_tools.showLoading(loading,$('#appstools_panel'),true,true);
				var reqdata={ offset: homeAPPsOffset, count: allNewAppsStartCount, orderBy:"Dummy String",filterBy:"Dummy String",mode:"Limited"};
				Workport.AppAPI.getHomeApp(getAppsToolsHomeListCallback,reqdata);
			},
			clickAllinMax:function(){
				allAPPSOffset = 0 ;
				homeAPPsOffset=0;
				wp_apps_tools.showLoading(loading,$('#appstools_panel'),false,false);
				var reqdata={offset:0,count:maxStartCount,filterBy:"Dummy String",orderBy:"Dummy String",mode:"Limited"};
				Workport.AppAPI.getAllApp(getAllAppsListCallback,reqdata);

			},
			clickAllinMin:function(){
				allAPPSOffset = 0 ;
				homeAPPsOffset=0;
				wp_apps_tools.showLoading(loading,$('#appstools_panel'),false,false);
				var reqdata={offset:0,count:minStartCount,filterBy:"Dummy String",orderBy:"Dummy String",mode:"Limited"};
				Workport.AppAPI.getHomeApp(getAppsToolsHomeListCallback,reqdata);
			},
			getHomeEndFlag:function(){
				return isEndHome;
			},
			geAllEndFlag:function(){
				return isEndAll;
			},
			refreshDeleteByPopWin:function(deleteId){
				var deleteIndex;
				for(var i=0;i++;i<oldAllAppList.length){
					if(oldAllAppList[i].AppID==deleteId){
						deleteIndex=i;
						break;
					}
				}
				if(deleteIndex>=0){
					oldAllAppList.splice(deleteIndex, 1);
					wp_apps_tools.render([],maxDataTmpl,maxPageTmpl);
					wp_apps_tools.render(appstools_handel_style_of_datasource(oldAllAppList,"oldmax"),maxDataTmpl,maxPageTmpl);
					shortDescription();
				}
			},
			refreshLikeByPopWin:function(appid,isLike,likeCount){
				var seletctIndex;
				for(var i=0;i<oldAllAppList.length;i++){
					if(oldAllAppList[i].AppID==appid){
						seletctIndex=i;
						break;
					}
				}
				if(seletctIndex>=0){
					oldAllAppList[seletctIndex].IsLiked=isLike;
					oldAllAppList[seletctIndex].LikesCount=likeCount;
					wp_apps_tools.render([],maxDataTmpl,maxPageTmpl);
					wp_apps_tools.render(appstools_handel_style_of_datasource(oldAllAppList,"oldmax"),maxDataTmpl,maxPageTmpl);
				}
			},
			refreshLaunchByPopWin:function(appid,launchCount){
				var seletctIndex;
				for(var i=0;i<oldAllAppList.length;i++){
					if(oldAllAppList[i].AppID==appid){
						seletctIndex=i;
						break;
					}
				}
				if(seletctIndex>=0){
					oldAllAppList[seletctIndex].LaunchCount=launchCount;
					wp_apps_tools.render([],maxDataTmpl,maxPageTmpl);
					wp_apps_tools.render(appstools_handel_style_of_datasource(oldAllAppList,"oldmax"),maxDataTmpl,maxPageTmpl);
				}
			},
			refreshAddOrEditByPopWin:function(){
				allAPPSOffset = 0 ;
				homeAPPsOffset=0;
				wp_apps_tools.render([],maxDataTmpl,maxPageTmpl);
				wp_apps_tools.showLoading(loading,$('#appstools_panel'),false,false);
				text = $.trim($('#apps_tools_search_keywords_input').val()); 
				
				if(text != ""){
					wp_apps_tools.searchTextTool(text);
					$("#apps_tools_search_keywords_input").val("");
				}else{
					if(tool_letter != ""){
						if(tool_letter == "All"){
							wp_apps_tools.render([],maxDataTmpl,maxPageTmpl);
		    	    		wp_apps_tools.clickAllinMax();
		    	    		if(useragent != 'ipad'){
		    	    			$('#appstools_min_panel_div').slimScroll({ scrollTo: '-500px',disableFadeOut:true });
		    	    		}
		    	    		$('#apps_tools_no_alpha_result').hide();
						}else{
							wp_apps_tools.searchLetterTool(tool_letter);
						}
					}else{
						var reqdata={offset:0,count:maxStartCount,filterBy:"Dummy String",orderBy:"Dummy String",mode:"Limited"};
						Workport.AppAPI.getAllApp(getAllAppsListCallback,reqdata);	
					}
				}
			},
			//------------------------------------------event-------------------------------
			searchLetterTool:function(letter){
				if(letter == "#")
					letter = "others";
				var reqdata = { offset: 0, count: 10,key:letter,mode:"StartsWith",orderBy:"Dummy String"};
				Workport.AppAPI.searchAllApp(function(searchData,searchHttpCode){
	    			loading.hide();
        	    	if(searchData.ResponseCode=="WP1022"){
        	    		shortDescription();
        	    		wp_apps_tools.render([],maxDataTmpl,maxPageTmpl);
        	    		wp_apps_tools.render(appstools_handel_style_of_datasource(searchData.GetApps,"max"),maxDataTmpl,maxPageTmpl);
        	    		$('#apps_tools_no_alpha_result').hide();
        	    	}else if(searchData.ResponseCode=="WP2021"){
        	    		wp_apps_tools.render([],maxDataTmpl,maxPageTmpl);
        	    		$('#apps_tools_no_alpha_result').text("No apps found starting with "+letter);
        	    		$('#apps_tools_no_alpha_result').css("left",279);
        	    		$('#apps_tools_no_alpha_result').show();
        	    	}else{
						Workport.utils.alertMsg("Error Message",searchData.ResponseMessage,function(_data){});
        	    	}
    	    	},reqdata);
    	    	letterSearchTool.update();
    	    	// letterSearchTool.cancleHighLight();
			},
			searchTextTool:function(text){
				var searchKey = $.param({key:$.trim(text)}).substring(4);
				var reqdata={offset:0,count:10,orderBy:"Dummy String",key:searchKey,mode:"Contains"};
				wp_contacts_main.render([],maxDataTmpl,maxPageTmpl);
				wp_apps_tools.showLoading(loading,$('#appstools_panel'),false,false);
				Workport.AppAPI.searchAllApp(function(data, httpCode){
					loading.hide();
					if(data){
						if(data.ResponseCode&&data.ResponseCode=="WP1022"){
							wp_apps_tools.render([],maxDataTmpl,maxPageTmpl);
							$('#apps_tools_search_zero_result').hide();
							var searchData=data.GetApps;
							$('#apps_tools_search_result_keywords').text($('#apps_tools_search_keywords_input').val());
							$('#apps_tools_search_result_count').text(searchData.length);
							$('#apps_tools_search_result_view').show();
							wp_apps_tools.render(appstools_handel_style_of_datasource(searchData,"max"),maxDataTmpl,maxPageTmpl);
							$('.app_tool_highlight').highlight($.trim($('#apps_tools_search_keywords_input').val()));
						}else if(data.ResponseCode=="WP2021"){
							$('#apps_tools_search_result_keywords').text($('#apps_tools_search_keywords_input').val());
							$('#apps_tools_search_result_count').text(0);
							$('#apps_tools_search_result_view').show();
							wp_apps_tools.render([],maxDataTmpl,maxPageTmpl);
							$('#apps_tools_search_zero_result').text("No results for "+$('#apps_tools_search_keywords_input').val()+".");
							$('#apps_tools_search_zero_result').show();
							$('.app_tool_highlight').highlight($.trim($('#apps_tools_search_keywords_input').val()));
						}else{
							Workport.utils.alertMsg(alert_title,data.ResponseMessage,function(_data){});
						}
					}
				},reqdata);
			},
			
			clickLike:function(element,appid) {
				var reqdata={appId:appid};
				Workport.AppAPI.saveLike(function(data, httpCode){
					if(data){
						if(data.ResponseCode&&data.ResponseCode=="WP1022"){
							if(data.IsLikedByMe){
								$(element).removeClass("app_tools_f_10_10");
								$(element).addClass("main_smartstream_t_8_8");
								$(element).attr("title","Unlike");
							}else{
								$(element).removeClass("main_smartstream_t_8_8");
								$(element).addClass("app_tools_f_10_10");
								$(element).attr("title","Like");
							}
							$(element).next().text("("+data.totalLikes+")");
							if(data.totalLikes>0){
								$(element).next().addClass("wp_appstools_hand");
							}else{
								$(element).next().removeClass("wp_appstools_hand");
							}
							for(var i=0;i<oldAllAppList.length;i++){
								if(oldAllAppList[i].AppID==appid){
									oldAllAppList[i].IsLiked=data.IsLikedByMe;
									oldAllAppList[i].LikesCount=data.totalLikes;
									break;
								}
							}
						}else{
							Workport.utils.alertMsg(alert_title,data.ResponseMessage,function(_data){});
						}
					}
				},reqdata);
			},
			clickBookMark:function(element,appid) {
		    	var reqdata={appId:appid};
				Workport.AppAPI.addFavourite(function(data, httpCode){
						if(data){
							if(data.ResponseCode&&data.ResponseCode=="WP1022"){
								if(data.Isfavourite){
									$(element).removeClass("main_smartstream_ac_8_8");
									$(element).addClass("main_smartstream_ab_8_8");
									$(element).prop("title", "Unbookmark");
								}else{
									$(element).removeClass("main_smartstream_ab_8_8");
									$(element).addClass("main_smartstream_ac_8_8");
									$(element).prop("title", "Bookmark");
								}
								for(var i=0;i<oldAllAppList.length;i++){
									if(oldAllAppList[i].AppID==appid){
										oldAllAppList[i].IsBookmarked=data.Isfavourite;
										break;
									}
								}
							}else{
								Workport.utils.alertMsg(alert_title,data.ResponseMessage,function(_data){});
							}
						}
				},reqdata);
			},

			openAPPDetail:function(element,appid) {
				appsAddDetailWinFunc.apps_add_detail_win_create(appid);
			},

			getLikedUsers:function(element,appid,likeCount) {
				if($(element).text()!="(0)"){
		    		var reqdata={appId:appid,count:10,offset:0};
					Workport.AppAPI.getLikeUser(function(data, httpCode){
						if(data){
							if(data.ResponseCode&&data.ResponseCode=="WP1022"){
								wp_all_liked_users.openUserListWindow(data.Likedusers);
							}else{
								Workport.utils.alertMsg(alert_title,data.ResponseMessage,function(_data){});
							}
						}
					},reqdata);
		    	}
			},
			openOrCloseSearchPanel:function(){
				$('#apps_tools_search_zero_result').hide();
				if($('#apptools').width()==256){
					$('#appstools_panel_resize_icon').click();
				}
				$("#apps_tools_search_keywords_input").val("");
				$('#apps_tools_search_view').toggle();
				if($('#apps_tools_search_view').is(":hidden")){
					$('.apps_order_button').show();
				}else{
					$('.apps_order_button').hide();
					$('#apps_tools_no_alpha_result').hide();
				}
			},
			closeSearchPanel:function(){
				$('#apps_tools_search_view').hide();
			},
			enterSearchBtn:function(event){
			    var keycode
			    if(window.event) // IE 
			    {
			        keycode = event.keyCode
			    }
			    else if(event.which) // Netscape/Firefox/Opera
			    {
			        keycode = event.which
			    }
			    if(keycode==13) //Enter key
			    {
			        /*var content=$('#apps_tools_search_keywords_input').val();
					if($.trim(content)==''){
						$("#apps_tools_search_keywords_input").kendoTooltip({
									content: 'Please input the keywords.' ,
									position: "right",
									showOn: false,
									show: function() {
        								isShowSreachKeywordsNull=true;
      								},
      								hide: function() {
        								isShowSreachKeywordsNull=false;
      								}
						});
						if(!isShowSreachKeywordsNull){
							$("#apps_tools_search_keywords_input").data('kendoTooltip').show();
						}
					}else{
						var reqdata={offset:0,count:10,orderBy:"Dummy String",key:encodeURI($.trim($('#apps_tools_search_keywords_input').val())),mode:"Contains"};
						Workport.AppAPI.searchAllApp(function(data, httpCode){
							if(data){
								if(data.ResponseCode&&data.ResponseCode=="WP1022"){
									wp_apps_tools.render([],maxDataTmpl,maxPageTmpl);
									$('#apps_tools_search_zero_result').hide();
									var searchData=data.GetApps;
									$('#apps_tools_search_result_keywords').text($('#apps_tools_search_keywords_input').val());
									$('#apps_tools_search_result_count').text(searchData.length);
									$('#apps_tools_search_result_view').show();
									wp_apps_tools.render(appstools_handel_style_of_datasource(searchData,"max"),maxDataTmpl,maxPageTmpl);
									$('.app_tool_highlight').highlight($.trim($('#apps_tools_search_keywords_input').val()));
								}else if(data.ResponseCode=="WP2021"){
									$('#apps_tools_search_result_keywords').text($('#apps_tools_search_keywords_input').val());
									$('#apps_tools_search_result_count').text(0);
									$('#apps_tools_search_result_view').show();
									wp_apps_tools.render([],maxDataTmpl,maxPageTmpl);
									$('#apps_tools_search_zero_result').text("No results for "+$('#apps_tools_search_keywords_input').val()+".");
									$('#apps_tools_search_zero_result').show();
									$('.app_tool_highlight').highlight($.trim($('#apps_tools_search_keywords_input').val()));
								}else{
									Workport.utils.alertMsg(alert_title,data.ResponseMessage,function(_data){});
								}
							}
						},reqdata);
					}*/
					this.clickSearchIcon();
			    }
		    },
		    clickSearchIcon:function(){
		    	letterSearchTool.update();
				letterSearchTool.cancleHighLight();
	    	    var content=$('#apps_tools_search_keywords_input').val();
				if($.trim(content)==''){
					$("#apps_tools_search_keywords_input").kendoTooltip({
								content: 'Please input the keywords.' ,
								position: "right",
								showOn: false,
								show: function() {
    								isShowSreachKeywordsNull=true;
  								},
  								hide: function() {
    								isShowSreachKeywordsNull=false;
  								}
					});
					if(!isShowSreachKeywordsNull){
						$("#apps_tools_search_keywords_input").data('kendoTooltip').show();
					}
					$("#apps_tools_search_keywords_input").on('input',function(e){
		    	   		$("#apps_tools_search_keywords_input").data('kendoTooltip').hide();  
					}); 
				}else{
					wp_apps_tools.searchTextTool($.trim($('#apps_tools_search_keywords_input').val()));
				}
		    },
		    clickBackToAll:function(){
		    	apps_tools_closeSearchPanel();
		    	wp_apps_tools.render([],maxDataTmpl,maxPageTmpl);
		    	// wp_apps_tools_enlargeIwantoPanel();
		    	wp_apps_tools.clickAllinMax();
		    },
		    clickAppIcon:function(element,appid,appurl){
		    	wp_apps_tools.showLoading(loading,$('#appstools_panel'),false,false);
		    	Workport.AppAPI.postLaunchCount(function(data, httpCode){
		    		loading.hide();
		    		if(data.ResponseCode=="WP1008"){
		    			window.open(appurl);
		    			if($('#apptools').width()>256){
		    			   $(element).parent().parent().find('.LaunchCount').text(data.UserLaunchCount+" Users");
		    			   for(var i=0;i<oldAllAppList.length;i++){
									if(oldAllAppList[i].AppID==appid){
										oldAllAppList[i].LaunchCount=data.UserLaunchCount;
										break;
									}
							}
		    			}
		    		}else{
		    			Workport.utils.alertMsg(alert_title,data.ResponseMessage,function(_data){});
		    		}
		    	},{appId:appid});
		    },
		    clickRegisterButton:function(){
		    	appsToolsCreateWin.apps_tools_win_create();
		    },
		    clickLaunchButton:function(){
		    	wp_app_edit_list.reset();
		    },
			//------------------------------------------event end-------------------------------
			//-----------------------------------------init function---------------------------------
			init:function(){
				$('#apps_tools_alpa_search').height(Workport.utils.getViewPort().height-100);
                var self = this;
                minPageTmpl.off("*");
                minPageTmpl.empty();
                if(!loading){loading = new Workport.Loader($('#appstools_panel'));}
                				
               	// $('#appstools_panel').appendTo('#apptools');
				$('#apptools').html($('#appstools_panel'));
				
				var width = $(window).width();
				var height = Screen.bodyHeight;
				$('.appstools_panel_div').css({
					width:"256",
					height:"100%"
				});
				if(useragent == 'ipad'){
					$('#appstools_min_panel_div').css('height',(height-60)+'px');
					$('#appstools_min_panel_div').css('overflow-y','scroll');
					$('#appstools_max_panel_div').css('height',(height-60)+'px');
					$('#appstools_max_panel_div').css('width','736px');
					$('#appstools_max_panel_div').css('overflow-y','scroll');
					$("#appstools_min_panel_div").bind("scroll",function(){
                        if(($("#appstools_min_panel_div")[0].scrollHeight <= $("#appstools_min_panel_div")[0].scrollTop + $("#appstools_min_panel_div").height())&&!self.getHomeEndFlag()){ // bottom
                            self.getNewHomeAppsList();
                        }
                    });
                    $("#appstools_max_panel_div").bind("scroll",function(){
                        if(($("#appstools_max_panel_div")[0].scrollHeight <= $("#appstools_max_panel_div")[0].scrollTop + $("#appstools_max_panel_div").height())&&!self.geAllEndFlag()){ // bottom
                            self.getNewAllAppsList();
                        }
                    });

				} else{
					$('#appstools_min_panel_div').slimScroll({
					 		height: (height-60)+'px',
							disableFadeOut:true
					 		
					});
					$('#appstools_max_panel_div').slimScroll({
						 		height: (height-65)+'px',
								disableFadeOut:true,
						 		width:'768px'
					});

					
					$('#appstools_min_panel_div').slimScroll().bind('slimscroll', function(e, pos){
			 				if(pos=="bottom"&&!wp_apps_tools.getHomeEndFlag()){
			 					wp_apps_tools.getNewHomeAppsList();
			 				}
					});

					$('#appstools_max_panel_div').slimScroll().bind('slimscroll', function(e, pos){
			 				if(pos=="bottom"&&!wp_apps_tools.geAllEndFlag()){
			 					wp_apps_tools.getNewAllAppsList();
			 				}
					});
				}
		        HomePage_Scrollable.registerZoomCallback(3, self.get_appstools_zoomin_cb, self.get_appstools_zoomout_cb);
				$('#appstools_panel_resize_icon').bind({
					click:function(e){
		                HomePage_Scrollable.zoom(3);
		                return;
					}
				});
				wp_apps_tools_decreaseIwantoPanel();
				var apps_tools_letter=Letter('#apps_tools_alpa_search',function(_letter){
					$("#apps_tools_search_view").hide();
					var reqdata;
					tool_letter = _letter;
					if(_letter=="#"){
						reqdata={ offset: 0, count: 10,key:"others",mode:"StartsWith",orderBy:"Dummy String"};
					}else{
						reqdata={ offset: 0, count: 10,key:_letter,mode:"StartsWith",orderBy:"Dummy String"};
					}
		    	    
		    	    if($('#apptools').width()==256){
		    	    	if(_letter=="All"){
		    	    		self.render([],minDataTmpl,minPageTmpl);
		    	    		self.clickAllinMin();
		    	    		if(useragent != 'ipad'){
		    	    			$('#appstools_min_panel_div').slimScroll({ scrollTo: '-500px',disableFadeOut:true });
		    	    		}
		    	    		$('#apps_tools_no_alpha_result').hide();
		    	    	}else{
		    	    		wp_apps_tools.showLoading(loading,$('#appstools_panel'),false,false,true);
		    	    		Workport.AppAPI.searchHomeApp(function(searchData,searchHttpCode){
		    	    			loading.hide();
			        	    	if(searchData.ResponseCode=="WP1022"){
			        	    		self.render([],minDataTmpl,minPageTmpl);
			        	    		self.render(appstools_handel_style_of_datasource(searchData.HomeApps,"min"),minDataTmpl,minPageTmpl);
			        	    		$('#apps_tools_no_alpha_result').hide();
			        	    	}else if(searchData.ResponseCode=="WP2021"){
			        	    		self.render([],minDataTmpl,minPageTmpl);
			        	    		$('#apps_tools_no_alpha_result').text("No apps found starting with "+_letter);
			        	    		$('#apps_tools_no_alpha_result').css("left",18);
			        	    		$('#apps_tools_no_alpha_result').show();
			        	    	}else{
			        	    		Workport.utils.alertMsg("Error Message",searchData.ResponseMessage,function(_data){});
			        	    	}
		        	    	},reqdata);
		    	    	}
		    	    	
		    	    }else{
		    	    	if(_letter=="All"){
		    	    		wp_apps_tools.render([],maxDataTmpl,maxPageTmpl);
		    	    		self.clickAllinMax();
		    	    		if(useragent != 'ipad'){
		    	    			$('#appstools_min_panel_div').slimScroll({ scrollTo: '-500px',disableFadeOut:true });
		    	    		}
		    	    		$('#apps_tools_no_alpha_result').hide();
		    	    	}else{
		    	    		wp_apps_tools.showLoading(loading,$('#appstools_panel'),false,false,true);
		    	    		Workport.AppAPI.searchAllApp(function(searchData,searchHttpCode){
		    	    			loading.hide();
			        	    	if(searchData.ResponseCode=="WP1022"){
			        	    		wp_apps_tools.render([],maxDataTmpl,maxPageTmpl);
			        	    		shortDescription();
			        	    		self.render(appstools_handel_style_of_datasource(searchData.GetApps,"max"),maxDataTmpl,maxPageTmpl);
			        	    		$('#apps_tools_no_alpha_result').hide();
			        	    	}else if(searchData.ResponseCode=="WP2021"){
			        	    		self.render([],maxDataTmpl,maxPageTmpl);
			        	    		$('#apps_tools_no_alpha_result').text("No apps found starting with "+_letter);
			        	    		$('#apps_tools_no_alpha_result').css("left",279);
			        	    		$('#apps_tools_no_alpha_result').show();
			        	    	}else{
									Workport.utils.alertMsg("Error Message",searchData.ResponseMessage,function(_data){});
			        	    	}
		        	    	},reqdata);
		    	    	}
		    	    }
				}, '#32a662');
				letterSearchTool=apps_tools_letter;
				apps_tools_letter.update();
                
            },

            showLoading: function(loader,element,isDown,iswhite,isblack){
				if(loader){
					if(isDown){
						loader.setContent(element,{
												position:'down',
												textCSS:{'display':'none','color':iswhite?'black':'white'}
						});
					}else{
						if(isblack){
							loader.setContent(element,{
								imgColor:'black',textCSS:{'color':'black'}, boxCSS:{'opacity':1}
							});
						}else{
							loader.setContent(element,{
									position:'center',
									textCSS:{'display':'inline','color':iswhite?'black':'white'}
							});
						}
					}
					loader.show();

				}
			},

            render: function(_data,dataTmpl,pageTmpl) {
            	if(_data && _data.length==0){
            		pageTmpl.off("*");
                    pageTmpl.empty();
            	}else{
            		var tmpl = kendo.template($.trim(dataTmpl.html()));
	                var arr = new Array();
	                $.map(_data, function(_elem) {
	                    arr.push(tmpl(_elem));
	                });
	                $(arr.join('')).appendTo(pageTmpl);
            	}
            }

			//-----------------------------------------init function end-------------------------------------


		};//rerurn end
    })();

    wp_apps_tools.init();
	
	function appAndToolsResize (){
		var height = $(window).height() - 110;
		$('#appstools_panel_div').height(Screen.bodyHeight);
		$('#apps_tools_alpa_search').height(height);
		$('#appstools_min_panel_div').height(height);
		$('#appstools_max_panel_div').height(height);
		$('#appstools_panel_div').find('.slimScrollDiv').height(height);
	}
	$(window).resize(appAndToolsResize);

	function onAPPDefaultThumbnailWanted(element) {
		  if (element == undefined) {
		      return;
		  }
		  $(element).attr('src', 'imgs/tmpicon.png');
	}
	
</script>
	
